/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.command;

import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;

/**
 * This class ia an implementation of Command interface.
 * Its "execute" method gets the current point of DrawingArea
 * and calls the "select" method of Controller.
 *
 * It does exists to be set as a command of the DrawingArea to do
 * selection on runtime.
 *
 * <br>Example:<br>
 * <pre>
 * SelectCommand selectCmd = new SelectCommandCommand(parent);
 * drawingArea.setClickedCommand(selectCmd);
 *</pre>
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @see    DrawingArea#getViewPoint
 */
public class SelectCommand implements Command {
    
    private InsaneInternalInterface parent;
    private DrawingArea da;
    
//*****************************************************************************
	
    /**
     * Creates new SelectCommand and gets the
     * DrawingArea from parent.
     *
     * @param   parent The parent JInternalFrame
     * @see    InsaneInternalInterface#getDrawing
     */
    public SelectCommand(JInternalFrame parent) {
        this.parent = (InsaneInternalInterface)parent;
        da = this.parent.getDrawing();
    }
    
//*****************************************************************************
	
    /**
     * Gets the DrawingArea current view point and calls
     * the "select" method on Controller.
     * Repaints drawing in order to color selection.
     *
     * @see    InsaneInternalInterface#getController
     */
    public void execute() {
        try{
            Point p = da.getViewPoint();
            parent.getController().select(p);
            da.repaint();
        }catch (Exception e) {
            Toolkit.getDefaultToolkit().beep();
            System.out.print(e.toString());
            JOptionPane.showMessageDialog(parent, e.toString(), "ERROR Message", JOptionPane.ERROR_MESSAGE);
        }
    }
    
//*****************************************************************************
	
    /**
     * Impossible to undo - not implemented.
     */
    public void undo() {}
    
//*****************************************************************************
	
    /**
     * Impossible to redo - not implemented.
     */
    public void redo() {}
    
//*****************************************************************************
}

